package com.yu.oss.config;

import com.yu.oss.service.StorageService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author 路亚
 * @version 0.1
 * @className StorageConfig
 * @description
 * @date 2025/1/9 20:25
 * @since jdk11
 */
@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${storage.type}")
    private String storageType;

    @Resource
    private StorageService minioStorageServiceImpl;

    @Resource
    private StorageService aliStorageServiceImpl;

    @Bean
    @RefreshScope
    public StorageService storageService(){
        if ("minio".equals(storageType)){
            return minioStorageServiceImpl;
        }else if ("ali".equals(storageType)){
            return aliStorageServiceImpl;
        }else {
            throw new RuntimeException("暂不支持该存储类型");
        }
    }
}
